package com.haierCamera.customapplication.api.repo;

import android.content.Context;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.haierCamera.customapplication.common.Resource;
import com.haierCamera.customapplication.utils.DataCacheUtils;

import javax.inject.Inject;

public class CacheRepo {

    @Inject
    Context context;

    @Inject
    public CacheRepo() {
    }

    public LiveData<Resource<String>> getCacheSize() {
        MutableLiveData<Resource<String>> liveData = new MutableLiveData();
        try {
            String cacheSize = DataCacheUtils.getTotalCacheSize(context);
            liveData.setValue(Resource.success(cacheSize));
        } catch (Exception e) {
            e.printStackTrace();
            liveData.setValue(Resource.error(100, e.getMessage(), null));
        }
        liveData.setValue(Resource.loading(null));
        return liveData;
    }

    public LiveData<Resource<String>> removeCache() {
        MutableLiveData<Resource<String>> liveData = new MutableLiveData();
        liveData.setValue(Resource.loading(null));
        try {
            DataCacheUtils.clearAllCache(context);
            liveData.setValue(Resource.success(null));
        } catch (Exception e) {
            e.printStackTrace();
            liveData.setValue(Resource.error(100, e.getMessage(), null));
        }
        return liveData;
    }
}
